package welsir.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Component;
import welsir.common.FlowerPool;
import welsir.entity.dos.UserRole;
import welsir.mapper.UserRoleMapper;
import welsir.security.enums.UserEnums;

import javax.annotation.Resource;

/**
 * @author Genius
 * @date 2023/03/07 23:15
 **/
@Component
public class RoleAuthUtil {
    @Resource
    UserRoleMapper userRoleMapper;

    /**
     * 判断用户是否有权限
     * @param uid      用户id
     * @param role     判定的权限id
     * @return
     */
    public boolean isAuth(Integer uid, UserEnums role){
        return userRoleMapper.selectCount(new QueryWrapper<UserRole>().eq("user_id",uid).eq("role_id",role.getRole())) > 0;
    }

    public UserRole getUserRole(Integer uid){
        return userRoleMapper.selectOne(new QueryWrapper<UserRole>().eq("user_id",uid));
    }

}
